package com.hushow.bus.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.hushow.bus.demo.dto.RouteInfo;
import com.hushow.bus.demo.event.RouteRemoteApplicationEvent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.cloud.bus.event.Destination;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "bus demo接口")
@RequestMapping("/message/")
public class BusDemoController {

    private final static String TOPIC="topic-demo";

    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    @GetMapping("/sendMessage")
    @ApiOperation(value = "发送", notes = "发送")
    public String list(@RequestParam("message") String message) {

        RouteInfo routeInfo = new RouteInfo().setServiceId("app-one-service").setStatus(1).setUri("/one/add").setUri("lb:app-one-service");

        ListenableFuture l = kafkaTemplate.send(TOPIC, routeInfo);
        return message;
    }

}
